#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2020 crane <crane@sharp>
#
# Distributed under terms of the MIT license.

"""

"""

class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def isSymmetrical(self, pRoot):
        if pRoot is None:
            return True     # 也有可能返回False, 看需求

        # 不要忘记return
        return self.rec_cmp(pRoot.left, pRoot.right)

    def rec_cmp(self, left, right):
        if left is None and right is None:
            return True

        if left is None or right is None:
            return False

        if left.val != right.val:
            return False

        # (左left, 右right).  (左right, 右left), 镜像对称
        return self.rec_cmp(left.left, right.right) and self.rec_cmp(left.right, right.left)

        # return s1 or s2


def test():
    s = Solution()

def main():
    print("start main")
    r = TreeNode(8)
    rl = TreeNode(6)
    rr = TreeNode(6)
    r.left, r.right = rl, rr

    l21 = TreeNode(5)
    l22 = TreeNode(7)
    l23 = TreeNode(7)
    l24 = TreeNode(5)

    rl.left, rl.right = l21, l22
    rr.left, rr.right = l23, l24

    s = Solution()
    ret = s.isSymmetrical(r)
    print(ret)

if __name__ == "__main__":
    main()
